package pl.gigiel.jme.behaviour.boidbody;

import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Pyramid;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;

public class SprinterBoid extends Node {
	private static final long serialVersionUID = 1L;
	private static final int SIZE = 1;
	private Node rootNode;

	public SprinterBoid(Node rootNode) {
		this.rootNode = rootNode;
		initAppearance();
		initController();
	}

	private void process(float elapsed) {
		System.out.println("Elapsed = " + elapsed);
		getLocalTranslation().addLocal(0.01f, 0.01f, 0.01f);
	}

	private void initAppearance() {
		TriMesh shape = new Pyramid(Pyramid.class.getName(), SIZE, SIZE);
		MaterialState material = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
		material.setDiffuse(ColorRGBA.red);
		shape.setRenderState(material);
		shape.updateRenderState();
		attachChild(shape);
		rootNode.attachChild(this);
	}

	private void initController() {
		addController(new Controller() {
			private static final long serialVersionUID = 1L;

			public void update(float elapsed) {
				process(elapsed);
			}
		});
	}
}
